using UnityEngine;
using System.Collections;

public class NetworkPhysicsSync : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
		if (stream.isWriting){
			Vector3 pos = transform.position;
			Quaternion rot = transform.rotation;
			Vector3 velocity = rigidbody.velocity;
			Vector3 angularVelocity = rigidbody.angularVelocity;

			stream.Serialize(ref pos);
			stream.Serialize(ref rot);
			stream.Serialize(ref velocity);
			stream.Serialize(ref angularVelocity);
		} 
		else{
			Vector3 receivedPosition = Vector3.zero;
			Quaternion receivedRotation = new Quaternion(0,0,0,0);
			Vector3 velocity = Vector3.zero;
			Vector3 angularVelocity = Vector3.zero;
			
			stream.Serialize(ref receivedPosition);
			transform.position = receivedPosition;
			stream.Serialize(ref receivedRotation);
			transform.rotation = receivedRotation;
			stream.Serialize(ref velocity);
			rigidbody.velocity = velocity;
			stream.Serialize(ref angularVelocity);
			rigidbody.angularVelocity = angularVelocity;
		}
	}
}
